package com.power.using.myapplication.view;

import android.content.ClipboardManager;
import android.content.Context;
import android.support.v7.widget.AppCompatEditText;
import android.text.InputType;
import android.util.AttributeSet;

/**
 * 项目名称:YZDSuperviseP
 * 创建人:zhangtainjia
 * 创建时间:2017/4/25 14:24
 */

public class PasteEdittext extends AppCompatEditText {
    private PasteEdittext mEdittext;

    private Context mContext;


    public PasteEdittext(Context context) {
        super(context);

        this.mContext=context;
        this.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
        this.setSingleLine(false);

//水平滚动设置为False
        this.setHorizontallyScrolling(false);
    }
    public PasteEdittext(Context context, AttributeSet attr){
        super(context,attr);
        this.mContext=context;
        this.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
        this.setSingleLine(false);

//水平滚动设置为False
        this.setHorizontallyScrolling(false);
    }
    public PasteEdittext getEdittext() {
        if (mEdittext==null){
            mEdittext=new PasteEdittext(mContext);
            mEdittext.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
            this.setSingleLine(false);

//水平滚动设置为False
            this.setHorizontallyScrolling(false);
        }else {
            return mEdittext;
        }
        return mEdittext;
    }

    @Override
    public boolean onTextContextMenuItem(int id) {
        switch (id){

            case android.R.id.paste:
                ClipboardManager clip= (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
                System.out.println(clip.getText());
                System.out.println("id:"+id);
                CharSequence patse=clip.getText();
                if (patse.length()>200){
//                    Toast toast = Toast.makeText(getContext(), "您输入的内容超过200个字，请重新输入", Toast.LENGTH_SHORT);
//                    toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL,0,0);
//                    toast.show();
                    this.getEdittext().setText(clip.getText());


                }

        }
        return super.onTextContextMenuItem(id);
    }


}
